/*
This software is distributed under the Simplified BSD License:

Copyright (c) 2008, Chris Venter <chris.venter@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, 
    	this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, 
    	this list of conditions and the following disclaimer in the documentation 
    	and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 
DAMAGE.
*/
#ifndef GENERIK_MINGW_H
#define GENERIK_MINGW_H

/** \file mingw.h
This file contains a couple of useful routines which seems to be missing
from the mingw compiler package.
*/

#ifdef __MINGW32__
//
// only use the following code under MinGW
//

#include <windows.h>
#include <generik/tracing.h>

/** sleeps for a number of seconds.
Windows defines the Sleep(int microseconds) function, so we misuse it here
to build a compatible sleep(unint seconds) function.
*/
inline void sleep(unsigned int n)
{
	REM_GENERIK_TRACER;
	GENERIK_TRACE("sleeping for "<<n<<" seconds");
	Sleep(1000 * n);
}

/** determines the number of configured processors.
This function is a GNU extension which lives in sys/sysinfo.h, so we define it
here as the value of the environment variable NUMBER_OF_PROCESSORS as defined
by windows.
*/
int get_nprocs_conf(void)
{
	const char* ncpus = getenv("NUMBER_OF_PROCESSORS");
	return atoi(ncpus);
}

#endif

#endif

